<?php
/*
*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
*/
include ("Mirrorbow.class.php");
$mb_device = new Mirrorbow();
$mb_device->mirrorbow_device = array("livingroom" => "192.168.1.68");

#!!entire port must be output
$mb_device->setPortDirection("livingroom",1,0);


if ($_POST['submit'] == "submit") {
    $submitArray = array();
    if ($_POST['bit0']) { $submitArray[0] = 1; } else { $submitArray[0] = 0; }
    if ($_POST['bit1']) { $submitArray[1] = 1; } else { $submitArray[1] = 0; }
    if ($_POST['bit2']) { $submitArray[2] = 1; } else { $submitArray[2] = 0; }
    if ($_POST['bit3']) { $submitArray[3] = 1; } else { $submitArray[3] = 0; }
    if ($_POST['bit4']) { $submitArray[4] = 1; } else { $submitArray[4] = 0; }
    if ($_POST['bit5']) { $submitArray[5] = 1; } else { $submitArray[5] = 0; }
    if ($_POST['bit6']) { $submitArray[6] = 1; } else { $submitArray[6] = 0; }
    if ($_POST['bit7']) { $submitArray[7] = 1; } else { $submitArray[7] = 0; }
#var_dump($submitArray);
    $mb_device->setPortValueFromBin("livingroom",1,$submitArray);
}

$binary_port = $mb_device->getPortValueToBin("livingroom", 1);

?>
<html>
    <body>
        <form action="exampleform.php" method="POST">
            PORT 1:<br />
            <input type="checkbox" name="bit0" <?php if($mb_device->getBitValue($binary_port, 0)) {echo "checked";} ?>> output 1 <br/>
            <input type="checkbox" name="bit1" <?php if($mb_device->getBitValue($binary_port, 1)) {echo "checked";} ?>> output 2 <br/>
            <input type="checkbox" name="bit2" <?php if($mb_device->getBitValue($binary_port, 2)) {echo "checked";} ?>> output 3 <br/>
            <input type="checkbox" name="bit3" <?php if($mb_device->getBitValue($binary_port, 3)) {echo "checked";} ?>> output 4 <br/>
            <input type="checkbox" name="bit4" <?php if($mb_device->getBitValue($binary_port, 4)) {echo "checked";} ?>> LED 1 <br/>
            <input type="checkbox" name="bit5" <?php if($mb_device->getBitValue($binary_port, 5)) {echo "checked";} ?>> LED 2 <br/>
            <input type="checkbox" name="bit6" <?php if($mb_device->getBitValue($binary_port, 6)) {echo "checked";} ?>> LED 3 <br/>
            <input type="checkbox" name="bit7" <?php if($mb_device->getBitValue($binary_port, 7)) {echo "checked";} ?>> LED 4 <br/>
            <input type="submit" value="submit" name="submit">
        </form>
    </body>
</html>